package book_management;

import book_management.book.BookList;
import book_management.user.AdminUser;
import book_management.user.NormalUser;
import book_management.user.User;

import javax.security.auth.login.LoginContext;
import java.util.NoSuchElementException;
import java.util.Scanner;

/**
 * 程序入口
 */
public class Main {
    public static void main(String[] args) {
        //此时图书馆只有一个书架
        BookList bookList = new BookList();
        //2用户登陆操作
        User user = login();
        while (true){
            int choic = user.menu();
            if (choic == -1){
                System.out.println("Byebye");
                break;
            }
            user.doOperation(bookList,choic);
        }
    }

    private static User login(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的用户名：");
        String str = scanner.nextLine();
        System.out.println("请输入您登录的角色，1表示普通用户，0表示管理员");
        int choice = scanner.nextInt();
        if (choice == 1){
            return  new NormalUser(str);
        }else if (choice == 0) {
            return new AdminUser(str);
        }
        throw new NoSuchElementException("键入有误，没有这个选项");

    }
}
